<meta charset="utf-8">
<title>城市代理商管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="description" content="网站描述">
<meta name="keywords" content="">
<meta name="author" content="wangl">
<link rel="icon" href="http://ow9lg82yy.bkt.clouddn.com/24f5c360-485d-4a6d-9468-2a61c353cf37.ico">
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all">
<link rel="stylesheet" href="/static/css/user.css" media="all">
<link rel="stylesheet" href="/static/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">


</head>
<body class="childrenBody">
<div>
    <div class="layui-form users_list">

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 60px;">所在区域</label>

            <div class="layui-col-md3">
                <label class="layui-form-label">请选择省:</label>
                <div class="layui-input-block">
                    <select name="province" id="province" lay-filter="province">

                    </select>
                </div>
            </div>
            <div class="layui-col-md3">
                <label class="layui-form-label">请选择市:</label>
                <div class="layui-input-block">
                    <select name="city" id="city" lay-filter="city">

                    </select>
                </div>
            </div>
            <div class="layui-col-md3">
                <label class="layui-form-label">请选择县/区:</label>
                <div class="layui-input-block">
                    <select name="district" id="district">
                    </select>
                </div>
            </div>

        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn" onclick="getAgentList()">搜索</button>
        </div>
        <div class="layui-inline">
            <#--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
        </div>
        <div class="layui-inline">
            <a href="addpage" class="layui-btn layui-btn-normal" data-type="addBlogArticle">新增代理商</a>
        </div>
        <div class="layui-form users_list">

                        <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
                            <thead>
                            <tr>
                                <#--1.编号、城市代理商昵称、手机号、所在区域（省市区）、佣金比例、累计佣金（CNY）、未结算佣金（CNY）、操作（编辑、冻结、重置密码、业绩订单）-->
                                <th data-field="id">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>编号</span></div>
                                </th>
                                <th data-field="nickName">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>城市代理商昵称</span></div>
                                </th>
                                <th data-field="tel">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>手机号</span></div>
                                </th>
                                <th data-field="address">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>所在区域（省市区）</span></div>
                                </th>
                                <th data-field="commRate">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>佣金比例</span></div>
                                </th>
                                <th data-field="cumulativeComm">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>累积佣金</span></div>
                                </th>
                                <th data-field="unsettledComm">
                                    <div class="layui-table-cell laytable-cell-1-anid1"><span>未结算佣金</span></div>
                                </th>
                                <th data-field="9">
                                <div class="layui-table-cell laytable-cell-1-9" align="center"><span>操作</span></div>
                                </th>
                            </tr>
                            </thead>
                            <tbody id="anList">
                            </tbody>
                        </table>
                        <div class="box-tools pull-right">
                            <ul class="pagination" id="pagination_ul">
                            </ul>
                        </div>

        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/tools.js"></script>
<script type="text/javascript" src="/static/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/static/js/CodeConstbonusList.js"></script>
<script type="text/javascript" src="/static/js/common.js"></script>
<script>

    function loadData(baseDto) {
        if (baseDto.code == ERROR)
            console.log(baseDto.msg);
        else {
            //数据
            var data = baseDto.data;
            var text = "";
            var opreate = "";
            $.each(data, function (index, bonus) {
                console.log(bonus);
                // // opreate = "<td>" + "<a href='/back/shareholder/freeze?type=" + 1 + "&userId=" + bonus.id + "' type=\"button\" class=\"layui-btn layui-btn-xs\">冻结</a>\n" + "</td>\n"
                opreate ="<td class=\"text-center\" align=\"center\">\n" +
                    "    <a href='/back/shareholder/freeze?type=" + 1 + "&userId=" + bonus.id + "'   type=\"button\" class=\"layui-btn layui-btn-xs\">冻结</a>\n" +
                    "    <a href='/back/shareholder/freeze?type=" + 2 + "&userId=" + bonus.id + "'  type=\"button\" class=\"layui-btn layui-btn-xs\">解冻</a>\n" +
                    "    <a href='/back/shareholder/reset/password?userId=" + bonus.id + "'  type=\"button\" class=\"layui-btn layui-btn-xs\">重置密码</a>\n" +
                    "    <a href='/back/agent/editpage?userId=" + bonus.id + "'  type=\"button\" class=\"layui-btn layui-btn-xs\">编辑</a>\n" +
                    "    <a href=''  type=\"button\" class=\"layui-btn layui-btn-xs\">业绩订单</a>\n" +
                    // "    <a href='/back/admin/admin/userCapitalPage?userType=1&userId=" + shareholderList.user.id + "'  type=\"button\" class=\"layui-btn layui-btn-xs\">资产详情</a>\n" +
                    "</td>\n"
                text += "<tr>\n" +
                    "<td>" + bonus.id + "</td>\n" +
                    "<td>" + bonus.nickName + "</td>\n" +
                    "<td>" + bonus.tel + "</td>\n" +
                    "<td>" + bonus.address + "</td>\n" +
                    "<td>" + bonus.commRate + "</td>\n" +
                    "<td>" + bonus.cumulativeComm + "</td>\n" +
                    "<td>" + bonus.unsettledComm + "</td>\n" +
                     opreate
                    "</tr>";
            });

            var bonusListDom = $("#anList");
            bonusListDom.empty();//清空子元素
            bonusListDom.append($(text));
//            var pages = baseDto.data.pages;
//            var pageNum = baseDto.data.pageNum;
//            var btnList = "";
//            btnList += "<li class='first_page'><a onclick='loadPage(this)' link='/back/shareholder/agent/list'>" + "首页" + "</a></li>";
//            var temp = "<li class='prepage'><a onclick='loadPage(this)' link='/back/shareholder/agent/list?pageNum=" + (pageNum - 1) + "'>上一页</a></li>";
//            console.log("temp=" + temp);
//            btnList += temp;
//            for (var i = 0; i < pages; i++) {
//                btnList += ("<li class='prepage'><a onclick='loadPage(this)' link='/back/shareholder/agent/list?pageNum=" + (i + 1) + "'>" + (i + 1) + "</a></li>\n")
//            }
//            btnList += ("<li class='nextpage'><a onclick='loadPage(this)' link='/back/shareholder/agent/list?pageNum=" + (pageNum + 1) + "'>下一页</a></li>\n" +
//                "<li class='last_page' ><a onclick='loadPage(this)' link='/back/shareholder/agent/list?pageNum=" + pages + "'>末页</a></li>");
//            console.log(btnList);
//            var pagination_ul = $("#pagination_ul");
//            pagination_ul.empty();
//            pagination_ul.append(btnList);
                layui.use("laypage",function () {
                    laypage = layui.laypage;
                    var newData = baseDto.data;
                    laypage.render({
                        elem: 'pagination_ul'
                        ,count: newData.length
                        ,curr: 1 //获取起始页
                        ,limit: 10
                        ,jump: function (obj) {
                            loadPage(obj.curr);
                        }

                    });
                });
        }
    }

    function loadPage(a) {
        var a_jquery = $(a);
        var url = a_jquery.attr("link");
        $.ajax(
            {
                url: url,
                type: "GET",
                success: function (baseDto) {
                    loadData(baseDto);
                }
            }
        );
    }


    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(*)', function (data) {
            window.location.href = '/back/agent/listpage';
        });
        $.ajax({
            async: false,
            url: '/area/province',
            type: 'get',
            success: function (baseDto) {
                var data = baseDto.data
                addSelect('province',data,true,'areaCode','areaName');
            }
        });

        // 一级联动事件触发
        form.on('select(province)', function(data){
            var value = data.value;
            $.ajax({
                async: false,
                url: '/area/city?provinceId='+ value,
                type: 'get',
                success: function (baseDto) {
                    var data = baseDto.data
                    addSelect('city',data,true,'areaCode','areaName');
                }
            });
            // areaState.area.fn(value);
        });

        // 二级联动事件触发
        form.on('select(city)', function(data){
            var value = data.value;
            $.ajax({
                async: false,
                url: '/area/district?cityId='+ value,
                type: 'get',
                success: function (baseDto) {
                    var data = baseDto.data
                    addSelect('district',data,true,'areaCode','areaName');
                }
            });
        });

        //select添加选项
        function addSelect(id,data,bool,val,text,region){
            //bool是否添加“请选择”选项
            val = val || 'type';
            text = text || 'name';
            var d="'"+region+"'";
            var html = '';
            var $id = $('#'+id);
            $id.html('');
            if(bool){html += '<option value="">请选择</option>';}
            for(var i in data){
                html +='<option value="'+data[i][val]+'">'+data[i][text]+'</option>';
            }
            $id.html(html);
            form.render("select");
        }
    });


    //获取数据
    $.ajax({
        url: "/back/shareholder/agent/list",
        type: "GET",
        success: function (baseDto) {
            loadData(baseDto);
        }
    });


    function getAgentList() {
        var province = $("#province").val();
        var city = $("#city").val();
        var district = $("#district").val();

        $.ajax({
            url: "/back/shareholder/agent/list",
            type: "GET",
            data:{
                province:province,
                city:city,
                district:district
            },
            success: function (baseDto) {
                loadData(baseDto);
            }
        });
        return baseDto;
    };

</script>


</html>